        var contractStore = new Ext.data.JsonStore({
    		url: '/weihe/getItems_contractList',
			root: 'datas',
			fields : [{
			        	   name:'contractId',mapping:'id'
			          },{
			        	   name:'contractName',mapping:'name'
			          },{
			        	   name:'contractSpecs',mapping:'specs'
			          },{
			        	   name:'contractQuantity',mapping:'quantity' 
			          },{
        				   name:'contractPrice',mapping:'price'
        			  },{
        				   name:'contractUnit',mapping:'unit'
        			  },{
        				   name:'contractAmount',mapping:'amount'
        			  }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_contractList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
        var contractListStore = new Ext.data.JsonStore({
			url: '/weihe/getList_contractList',
			root: 'datas',
			fields : [{
			        	   name:'contractListId',mapping:'id'
			          },{
			        	   name:'contractListNum',mapping:'listNum' 
			          },{
			        	   name:'contractShoufang',mapping:'shoufang' 
			          },{
			        	   name:'contractSeller',mapping:'seller' 
			          },{
			        	   name:'contractSaddr',mapping:'saddr' 
			          },{
			        	   name:'contractSdizhi',mapping:'sdizhi' 
			          },{
			        	   name:'contractStell',mapping:'stel' 
			          },{
			        	   name:'contractMaifang',mapping:'maifang' 
			          },{
			        	   name:'contractBuyer',mapping:'buyer' 
			          },{
			        	   name:'contractBaddr',mapping:'baddr' 
			          },{
			        	   name:'contractBdizhi',mapping:'bdizhi' 
			          },{
			        	   name:'contractBtell',mapping:'btel' 
			          },{
			        	   name:'contractNum',mapping:'num' 
			          },{
        				   name:'contractDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
			        	   name:'contractDidian',mapping:'didian' 
			          },{
			        	   name:'contractLocation',mapping:'location' 
			          },{
			        	   name:'contractSud',mapping:'sud' 
			          },{
			        	   name:'contractCong',mapping:'cong' 
			          },{
			        	   name:'contractDao',mapping:'dao' 
			          },{
			        	   name:'contractFrom',mapping:'f' 
			          },{
			        	   name:'contractTo',mapping:'t' 
			          },{
			        	   name:'contractTiaojian',mapping:'tiaojian' 
			          },{
			        	   name:'contractPayment',mapping:'payment' 
			          },{
			        	   name:'contractQita',mapping:'qita' 
			          },{
			        	   name:'contractOther',mapping:'other' 
			          },{
			        	   name:'contractTotal',mapping:'total' 
			          }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_contractList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
       
        
contracts = function(){
	
	var tmp='';

	
  return{
	  
	  
		listPanel : function(){
	  
		var listPanel = new Ext.Panel( {
			                    region : 'north',
			                    layout : 'border',
			                    frame  : true,
			                    height :250,
			                    items  : [contracts.listGrid(),contracts.listForm()] 
		                      });
	  
	  return listPanel;
},

listForm : function(){
	  
    


		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
				progressConsole();
				if(listForm.form.isValid()){ 
					Ext.getCmp("contractsForm").buttons[0].enable();
					Ext.getCmp("contractsForm").buttons[1].enable();
					Ext.getCmp("contractsForm").buttons[2].enable();
					if (listForm.form.findField("contractListId").getValue() == "") {
						 listForm.form.submit({
						     url : '/weihe/add_contractList',
						     success : function(form, action) {
							       if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								        Ext.Msg.alert('消息', action.result.msg, function() {
								        Ext.getCmp("contractListForm").form.findField('contractList.id').setValue(action.result.contractList_id);
									    Ext.getCmp("contractsForm").form.findField('contractList.id').setValue(action.result.contractList_id);
									    Ext.getCmp("contractListGrid").getStore().load({params : {start : action.result.total-1, limit : 5}});
									    listForm.buttons[0].setText('修改');
								        })
							       }
						     }
					      })
					}else {
							listForm.form.submit({
								url : '/weihe/update_contractList',
								success : function(form, action) {
									if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
										Ext.Msg.alert('消息', action.result.msg, function() {
											Ext.getCmp("contractListGrid").getStore().load({params : {start : 0, limit : 5}});
										})
									}
							   }
							})
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		});

	var button_clear = new Ext.Button({
		text : '清空',
		handler : function() {
		
			listForm.form.reset();
			listForm.buttons[0].setText('添加');
			Ext.getCmp("contractsForm").form.reset();
			Ext.getCmp("contractsForm").buttons[0].disable();
		    Ext.getCmp("contractsForm").buttons[1].disable();
		    Ext.getCmp("contractsForm").buttons[2].disable();
		    Ext.getCmp("contractGrid").getStore().removeAll();
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = listForm.form.findField('contractListId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_contractList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									listForm.form.reset();
								    listForm.buttons[0].setText('添加');
						  }else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("contractListGrid").getStore().load({params : {start : 0, limit : 5}});
								listForm.form.reset();
								listForm.buttons[0].setText('添加');
							});
						  }
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'contractList.id' : listForm.form.findField('contractListId').getValue() }
				});
			}
		}
	});
	
	  
			var listForm = new Ext.form.FormPanel({
			id : 'contractListForm',
			region : 'east',
			title : '合同信息',
			frame : true,
			width : 330,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 85,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{  // Ext.form.Hidden
				id: 'contractListId',
				xtype : 'hidden',  // 隐藏的表单
				name : 'contractList.id'
			},{
				id: 'contractShoufang',
				fieldLabel: "卖方",
				name: "contractList.shoufang"
			},{
				id: 'contractSeller',
				fieldLabel: "Sellers",
				name: "contractList.seller"
			},{
				id: 'contractSdizhi',
				fieldLabel: "卖方地址",
				name: "contractList.sdizhi"
			},{
				id: 'contractSaddr',
				fieldLabel: "SellAddr",
				name: "contractList.saddr"
			},{
				id: 'contractStell',
				fieldLabel: "卖方电话",
				name: "contractList.stel"
			},{
				id: 'contractMaifang',
				fieldLabel: "买方",
				name: "contractList.maifang"
			},{
				id: 'contractBuyer',
				fieldLabel: "Buyers",
				name: "contractList.buyer"
			},{
				id: 'contractBdizhi',
				fieldLabel: "买方地址",
				name: "contractList.bdizhi"
			},{
				id: 'contractBaddr',
				fieldLabel: "BuyAddr",
				name: "contractList.baddr"
			},{
				id: 'contractBtell',
				fieldLabel: "买方电话",
				name: "contractList.btel"
			},{
				id: 'contractNum',
				fieldLabel: "号码",
          	    name: "contractList.num"
			},{
				id: 'contractDate',
                xtype: 'datefield',
                fieldLabel: "日期", //第三行，出生日期 
                format : 'Y-m-d',
    			allowBlank:false,
                name: "contractList.date"
			},{
				id: 'contractDidian',
				 fieldLabel: "签约地点",
                 name: "contractList.didian"
			},{
				id: 'contractLocation',
				 fieldLabel: "Signed_at",
                name: "contractList.location"
			},{
				id: 'contractSud',
				 fieldLabel: "SAYUSDOLLARS",
                name: "contractList.sud"
			},{
				id: 'contractCong',
				fieldLabel: "从",
                name: "contractList.cong"
			},{
				id: 'contractDao',
			    fieldLabel: "到",
	            name: "contractList.dao"
			},{
				id: 'contractFrom',
				fieldLabel: "from",
		        name: "contractList.f"
			},{
				id: 'contractTo',
				fieldLabel: "to",
		        name: "contractList.t"
			},{
				id: 'contractTiaojian',
				fieldLabel: "付款条件",
		        name: "contractList.tiaojian"
			},{
				id: 'contractPayment',
				fieldLabel: "Payment",
		        name: "contractList.payment"
			},{
				id: 'contractQita',
				fieldLabel: "其他",
		        name: "contractList.qita"
			},{
				id: 'contractOther',
				fieldLabel: "Others",
		        name: "contractList.other"
			},{
				id: 'contractTime',
                xtype: 'datefield',
                fieldLabel: "装运日期", //第三行，出生日期 
                format : 'Y-m-d',
    			allowBlank:false,
                name: "contractList.time"
			}],
			buttons : [button_add,button_clear,button_del]
	});
	  
	  return listForm;
},  
	  
	  
  listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : contractListStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var listGrid = new Ext.grid.GridPanel({
		   id:'contractListGrid',
		   region : 'center',
		   minColumnWidth : 35,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   tbar:[{
			  	text:"打印合同",
				handler:function(){
							if(tmp!=''){
			   				window.open('/weihe/printContract?contractList.id='+ tmp, '_blank');
			   				tmp = '';
							}else{
								Ext.Msg.alert('提示','请选择要打印的数据!');
							}
				}
						
		   		},"-"],
		   store : contractListStore,
		   columns: [
		             {header : '单号', dataIndex : 'contractListNum'},
		             {header : '卖方', dataIndex : 'contractShoufang'},
		             {header : 'Sellers', dataIndex : 'contractSeller'},
		             {header : '卖方地址', dataIndex : 'contractSdizhi'},
		             {header : 'SellAddr', dataIndex : 'contractSaddr'},
		             {header : '卖方电话', dataIndex : 'contractStell'},
		             {header : '买方', dataIndex : 'contractMaifang'},
		             {header : 'Buyers', dataIndex : 'contractBuyer'},
		             {header : '买方地址', dataIndex : 'contractBdizhi'},
		             {header : 'BuyAddr', dataIndex : 'contractBaddr'},
		             {header : '买方电话', dataIndex : 'contractBtell'},
		             {header : '号码', dataIndex : 'contractNum'},
		             {header : '日期', dataIndex : 'contractDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : '签约地点', dataIndex : 'contractDidian'},
		             {header : 'Signed_at', dataIndex : 'contractLocation'},
		             {header : 'SAYUSDOLLARS', dataIndex : 'contractSud', menuDisabled : true},
		             {header : '从', dataIndex : 'contractCong'},
		             {header : '到', dataIndex : 'contractDao'},
		             {header : 'From', dataIndex : 'contractFrom'},
		             {header : 'TO', dataIndex : 'contractTo'},
		             {header : '付款条件', dataIndex : 'contractTiaojian', menuDisabled : true},
		             {header : 'Payment', dataIndex : 'contractPayment', menuDisabled : true},
		             {header : '其他', dataIndex : 'contractQita', menuDisabled : true},
		             {header : 'Other', dataIndex : 'contractOther', menuDisabled : true},
		             {header : 'Total', dataIndex : 'contractTotal', menuDisabled : true},
		             {header : '装运期', dataIndex : 'contractDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')}
		             ],
         sm : rowSelectionModel,
         listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		tmp = record.id;
			   		Ext.getCmp("contractListForm").form.loadRecord(record);
			   		Ext.getCmp("contractsForm").form.findField('contractList.id').setValue(record.id);
			   		Ext.getCmp("contractsForm").buttons[0].enable();
					Ext.getCmp("contractsForm").buttons[1].enable();
					Ext.getCmp("contractsForm").buttons[2].enable();
					Ext.getCmp("contractListForm").buttons[0].setText('修改');
					Ext.getCmp("contractGrid").getStore().baseParams = {'contractList.id': record.id};
					Ext.getCmp("contractGrid").getStore().load({params : {start : 0, limit : 5}});
		   		}
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
  
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : contractStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'contractGrid',
		   title : '货物信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : contractStore,
		   columns: [
		             {header : '商品名称', dataIndex : 'contractName', menuDisabled : true},
		             {header : '商品规格', dataIndex : 'contractSpecs', menuDisabled : true},
		             {header : '商品单位', dataIndex : 'contractUnit', menuDisabled : true},
		             {header : '商品数量', dataIndex : 'contractQuantity', menuDisabled : true},
		             {header : '价格', dataIndex : 'contractPrice', menuDisabled : true},
		             {header : '金额', dataIndex : 'contractAmount', menuDisabled : true}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   Ext.getCmp("contractsForm").form.loadRecord(record);
			   Ext.getCmp("contractsForm").buttons[0].setText('修改');
			  
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
	contractsForm : function(){
		
		

		var button_add = new Ext.Button({
			text : '添加',
			disabled : true,
			handler : function() {
					progressConsole();
				if(contractsForm.form.isValid()){ 	
					if (contractsForm.form.findField("contractItem.id").getValue() == "") {
						contractsForm.form.submit({
						  url : '/weihe/addItem_contractList',
						   success : function(form, action) {
							 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							  }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									 var i = contractsForm.form.findField('contractList.id').getValue();
									   contractsForm.form.reset();
									   contractsForm.form.findField('contractList.id').setValue(i);
									   Ext.getCmp("contractGrid").getStore().baseParams = {'contractList.id': i};
									   Ext.getCmp("contractGrid").getStore().load({params : {start : 0, limit : 5}});
									   Ext.getCmp("contractListGrid").getStore().reload();
								});
							  }
						    },
						    failure : function(form, action) {
      							Ext.Msg.alert('错误', action.result.msg);
      						}
					    });
					}else {
						contractsForm.form.submit({
							  url : '/weihe/updateItem_contractList',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = contractsForm.form.findField('contractList.id').getValue();
										contractsForm.form.reset();
										 contractsForm.form.findField('contractList.id').setValue(i);
										 Ext.getCmp("contractGrid").getStore().reload();
										 Ext.getCmp("contractListGrid").getStore().reload();
										 contractsForm.buttons[0].setText('添加');
										
									})
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    })

				
						
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		text : '清空',
		disabled : true,
		handler : function() {
		var i = contractsForm.form.findField('contractList.id').getValue();
			contractsForm.form.reset();
			contractsForm.form.findField('contractList.id').setValue(i);
		    contractsForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		disabled : true,
		handler : function() {
			var id = contractsForm.form.findField('contractItem.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/deleteItem_contractList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									var i = contractsForm.form.findField('contractList.id').getValue();
								contractsForm.form.reset();
								contractsForm.form.findField('contractList.id').setValue(i);
								contractsForm.buttons[0].setText('添加');
						  }else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("contractGrid").getStore().load({params : {start : 0, limit :5}});
								var i = contractsForm.form.findField('contractList.id').getValue();
								contractsForm.form.reset();
								contractsForm.form.findField('contractList.id').setValue(i);
								contractsForm.buttons[0].setText('添加');
								Ext.getCmp("contractListGrid").getStore().reload();
							});
						}
					  }
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'contractItem.id': id , 'contractList.id' : contractsForm.form.findField('contractList.id').getValue() }

				});
			}
		}
	});
	
		var contractsForm = new Ext.form.FormPanel({
			id : 'contractsForm',
			title : '货物信息',
			frame : true,
			width : 300,
			region : 'east',
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{  // Ext.form.Hidden
				id: 'contractId',
				xtype : 'hidden',  // 隐藏的表单
				name : 'contractItem.id'
			},{  // Ext.form.Hidden
				xtype : 'hidden',  // 隐藏的表单
				name : 'contractList.id'
			},{
				id:'contractName',
				fieldLabel : '商品名称',
				allowBlank:false,
				name : 'contractItem.name',
				blankText:'请输入商品名称'
			},{
				id:'contractSpecs',
				fieldLabel : '商品规格',
				allowBlank:false,
				name : 'contractItem.specs',
				blankText:'请输入商品规格'
			},{
				id:'contractUnit',
				fieldLabel : '商品单位',
				allowBlank:false,
				name : 'contractItem.unit',
				blankText:'请输入商品单位'
			},{
				id:'contractQuantity',
				fieldLabel : '数量',
				name : 'contractItem.quantity',
				allowBlank:false,
				blankText:'请输入数量',
				regex : /^[1-9]\d*$/,
			    regexText:'请输入有效的数量' 
			},{
				id:'contractPrice',
				fieldLabel : '单价',
				allowBlank:false,
				name : 'contractItem.price',
				blankText:'请输入单价',
				regex : /^\d+(\.\d+)?$/,
			    regexText:'请输入有效的价格'   
			}],
			buttons : [button_add,button_clear,button_del]
		
	});
		return contractsForm;
	}
  }
}();








